import { apiBaseUrl } from "../config/config.js";
import axios from 'axios'
import { getToken } from '../utils/storage.js'


/**
 * @description 使用Promise对axios()进行的二次封装
 * @param {Object} opts 请求配置参数，格式：{url:'',method:'',data:{}}
 */

export function srvHttp(opts = {}) {
    let token = getToken() || '';
    return new Promise((resolve, reject) => {
        axios({
            url: apiBaseUrl + opts.url,
            method: opts.method || 'GET',
            data: opts.data || {},
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
                'Authorization': token || ''
            },

        }).then(res => {

            resolve(res)
        })
    });

}